var win = Ti.UI.currentWindow;

// Create a second table view section, a collection of cold beverages, populated from a database
var coldTableViewSection = Titanium.UI.createTableViewSection({headerTitle:'Childrens'});

// First, create a database connection, creating the database if it doesn't yet exist
var coldDB = Titanium.Database.open('dagboksDB');



// If it already exists, we will be using the existing data from a previous execution of the app
coldDB.execute('CREATE  TABLE  IF NOT EXISTS children (childname TEXT)');


coldDB.execute('INSERT INTO children (childname) VALUES(?)', 'olle');
coldDB.execute('INSERT INTO children (childname) VALUES(?)', 'johan');

var myResultSet = coldDB.execute('SELECT * FROM children');
  if (!myResultSet.isValidRow()) {
    coldDB.execute('INSERT INTO children (childname) VALUES(?)', 'All');
    //coldDB.execute('SELECT * FROM childs WHERE CHILDNAME=?'); 
  }
myResultSet.close();

// Create a TableView row for each cold beverage in the database table
var myResultSet = coldDB.execute('SELECT * FROM children');
//if (myResultSet) {
  while (myResultSet.isValidRow()) {
    coldTableViewSection.add(Titanium.UI.createTableViewRow({
      title:myResultSet.fieldByName('childname')
    }));

    myResultSet.next();
  }
//}
  
//myResultSet.close();// Finished with the result set
//coldDB.close();// Finished with the database for now

// Create a TableView; we'll add the row data later
var myTableView = Titanium.UI.createTableView({
style:Titanium.UI.iPhone.TableViewStyle.GROUPED
});

// Add the hot and cold sections to the TableView, as well as the action buttons
myTableView.setData([coldTableViewSection]);

// Add the table to the window and open it*/
win.add(myTableView);
win.open();